package com.ruoyi.machine.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.machine.mapper.MachineMapper;
import com.ruoyi.machine.domain.Machine;
import com.ruoyi.machine.service.IMachineService;

import javax.annotation.Resource;

/**
 * 设备概览Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-15
 */
@Service
public class MachineServiceImpl implements IMachineService 
{
    @Resource
    private MachineMapper machineMapper;

    /**
     * 查询设备概览
     * 
     * @param machineId 设备概览主键
     * @return 设备概览
     */
    @Override
    public Machine selectMachineByMachineId(Long machineId)
    {

        return machineMapper.selectMachineByMachineId(machineId);
    }

    /**
     * 查询设备概览列表
     * 
     * @param machine 设备概览
     * @return 设备概览
     */
    @Override
    public List<Machine> selectMachineList(Machine machine)
    {
        return machineMapper.selectMachineList(machine);
    }

    /**
     * 新增设备概览
     * 
     * @param machine 设备概览
     * @return 结果
     */
    @Override
    public int insertMachine(Machine machine)
    {
        return machineMapper.insertMachine(machine);
    }

    /**
     * 修改设备概览
     * 
     * @param machine 设备概览
     * @return 结果
     */
    @Override
    public int updateMachine(Machine machine)
    {
        //查看机器当前状态
        Machine cur = machineMapper.selectMachineByMachineId(machine.getMachineId());
        Date date = new Date();
        long state = machine.getMachineState();
        if(state != cur.getMachineState()){
            if(state == 1) machine.setStartTime(date);
            else machine.setEndTime(date);
        }
        return machineMapper.updateMachine(machine);
    }

    /**
     * 批量删除设备概览
     * 
     * @param machineIds 需要删除的设备概览主键
     * @return 结果
     */
    @Override
    public int deleteMachineByMachineIds(Long[] machineIds)
    {
        return machineMapper.deleteMachineByMachineIds(machineIds);
    }

    /**
     * 删除设备概览信息
     * 
     * @param machineId 设备概览主键
     * @return 结果
     */
    @Override
    public int deleteMachineByMachineId(Long machineId)
    {
        return machineMapper.deleteMachineByMachineId(machineId);
    }
}
